import apiClient from '@/lib/interceptor';

// 获取所有员工的请假申请
export const getLeaveRequest = (params) => {
  return apiClient.get('/approval', {
    params: {
      page: params.page,  // 修改这里
      pageSize: params.pageSize,  // 修改这里
      deptId: params.deptId,
      type: params.type,
      approvalStatus: params.approvalStatus,
    },
  });
};

// 提交审批请假结果
export const saveApproval = (approvalData) => {
  return apiClient.patch('/approval', approvalData);
};

// 提交审批销假结果
export const updateRevokeStatus = (revokeData) => {
  return apiClient.patch('/approval', revokeData);
};

// 提交审批延期结果
export const updateExtensionStatus = (ExtensionData) => {
  return apiClient.patch('/approval', ExtensionData);
};

// 定义审批请求参数接口
export interface ApproveRecruitmentPlanParams {
    planId: number;
    approveStatus: number;  // 0:发布未审批 1:修改未审批 2:已通过 3:已拒绝
}

// 添加 ApiResponse 类型定义
interface ApiResponse<T> {
  code: number;
  msg: string;
  data: T;
}

/**
 * 审批招聘计划
 * @param params 审批参数
 * @returns 审批结果
 */
export const approveRecruitmentPlan = async (params: ApproveRecruitmentPlanParams) => {
    try {
        const response = await apiClient.patch<ApiResponse<null>>(
            '/approval/recruit/announcements',
            params
        );
        return response.data;
    } catch (error) {
        console.error('审批招聘计划失败:', error);
        throw error;
    }
};